#include "view_rec_dialog.h"

using namespace std;

ViewRecDialog::ViewRecDialog( QWidget * parent, Qt::WFlags f) 
	: QDialog(parent, f)
{
	//Setup gui
	setupUi(this);
	
	//connect the buttons to the functions when clicked
	connect(printrecPbtn, SIGNAL(clicked()), this, SLOT(printRec()));
	connect(exitPbtn, SIGNAL(clicked()), this, SLOT(doneClicked()));
}

void ViewRecDialog::information (QString title, QString desc, QString ingre, QString direc, 
	                             QString nums, QString prep, QString cook, QString totalT, 
	                             QString cal)
{
	titleEdit->setText(title);
	descEdit->setText(desc);
	ingredEdit->setText(ingre);
	directEdit->setText(direc);
	numServ->setText(nums);
	prepEdit->setText(prep);
	cookEdit->setText(cook);
	totalTime->setText(totalT);
	calEdit->setText(cal);
}

 void ViewRecDialog::printRec()
 {
     QTextEdit *editor = new QTextEdit();
     editor->setText("Title: " + titleEdit->text() + "\n \n");
     editor->append("Description: " + descEdit->toPlainText() + "\n \n");
     editor->append("Ingredients: \n");
     editor->append(ingredEdit->toPlainText() + "\n");
     editor->append("Directions: \n");
     editor->append(directEdit->toPlainText() + "\n");
     editor->append("Number of Servings: " + numServ->text() + "\n");
     editor->append("Prep-Time: " + prepEdit->text() + " mins \n");
     editor->append("Cook-Time: " + cookEdit->text() + " mins \n");
     editor->append("Ready-Time: " +  totalTime->text() + " mins \n");
     editor->append("Calories: " + calEdit->text() + "\n");
     QPrinter printer;

     QPrintDialog *dialog = new QPrintDialog(&printer, this);
     dialog->setWindowTitle(tr("Print Document"));
     if (dialog->exec() != QDialog::Accepted)
         return;

     editor->print(&printer);
 }
 
 void ViewRecDialog::doneClicked()
//Post: Exits the dialog
{
	this->close();
}
